﻿using T4UtilityBelt.Writers;

namespace T4UtilityBelt.UxDesigns.Screens.Renders.ViewModel
{
    public class EntityListScreenRenderer : IEntityListScreenRenderer
    {
        public void RenderParentClass(EntityListScreen control, CodeWriter writer)
        {
            writer.Write(string.Format("ListEntityViewModel<{0}Model, {0}Entity, {0}ReadEntityViewModel>", control.EntityName));
        }


        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "ICommand")]
        public void RenderCode(EntityListScreen control, CodeWriter writer)
        {
            writer.Write(string.Format(@"
        public override ICommand ItemSelectedCommand
        {{
            get
            {{
                return new MvxRelayCommand<{0}ReadEntityViewModel>(
                    (e) => RequestNavigate<{0}ReadEntityViewModel>(
                        new {0}ModelParameters() {{ Id = e.Data.Id }}
                        )
                    );
            }}
        }}

        public override ICommand AddCommand
        {{
            get
            {{
                return new MvxRelayCommand(OnAdd);
            }}
        }}

        private void OnAdd()
        {{
            RequestNavigate<{0}UpdateEntityViewModel>(new {0}ModelParameters());
        }}
", control.EntityName));
        }

        public void RenderControls(EntityListScreen control, CodeWriter writer)
        {
            control.Controls.RenderViewModelCs(writer);
        }

    }
}
